home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15620 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.unix.programmer
  4. Subject: Re: Q: '\n' character  -  Making a better fgets?
  5. Date: 19 Apr 1996 18:58:39 -0700
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4l9gcfINN9at@keats.ugrad.cs.ubc.ca>
  8. References: <31616F63.481D@lava.weeg.uiowa.edu> <4l6flq$rck@mark.ucdavis.edu> <4l8dmuINN6lf@keats.ugrad.cs.ubc.ca> <4l92qh$ft7@mark.ucdavis.edu>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <4l92qh$ft7@mark.ucdavis.edu>,
  12. James Knight <knight@quad.cs.ucdavis.edu> wrote:
  13. >You were right about the getc/putc version versus the fgetc/fgetc
  14. >version, but that isn't what suprised me.  What suprised me was that
  15. >the my_getline version, with it's use of fgets and strlen, was 
  16. >faster than the getc/putc version.  I wrote my_getline for simplicity,
  17. >to make an easier to use fgets, not for speed (since I still don't
  18. >have the same intuitive understanding for optimization that I do for
  19. >programming).  So, the question I have is why did version 4 run
  20. >faster than version 2?  From looking at the respective codes and with
  21. >my understanding of getc/putc versus fgets/strlen, it shouldn't have.
  22.  
  23. It's quite weird. I don't understand it myself, at first glance.  Care to
  24. report user and system times as well as elapsed times in your test? This could
  25. be more telling, since elapsed time can vary randomly due to system activities.
  26.  
  27. I suspect that the elapsed times are due to I/O transfer time more than to CPU
  28. usage. My own test of freadln() on a Linux system showed about 40-90% CPU usage
  29. depending on the nature of the file (very short lines -> heavy CPU, long lines
  30. -> lower CPU usage).
  31.  
  32. BTW I had not noticed on first reading that you included the freadln() function
  33. in your test! What have you DONE to my TABS? :))
  34.  
  35. It doesn't fare all that badly considering its bloated generality.
  36.